import java.util.ArrayList;
import java.util.HashSet;
import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class TestTiles {
    static Set<String> set = new HashSet<>();

    static void fn(List<Character> list, int i) {
        if (i == list.size() - 1)
        {
            set.add(String.valueOf(list.subList(0,i+1)));//System.out.println(list);// return String.valueOf(list);
            return;
        }
            //set.add(String.valueOf(list));//System.out.println(list);// return String.valueOf(list);

        for (int j = i; j < list.size(); j++) {
            set.add(String.valueOf(list.subList(i,j+1)));
            swap(list, i, j);
            set.add(String.valueOf(list.subList(i,j+1)));
            fn(list, i + 1);
            set.add(String.valueOf(list.subList(i,j+1)));
            swap(list, j, i);
        }

    }

    public static void swap(List<Character> list, int i, int j) {
        char temp = list.get(i);
        list.set(i, list.get(j));
        list.set(j, temp);
    }

    public static void main(String[] args) {
        String str = "AAB";
        char[] chars = str.toCharArray();
        List<Character> list = new ArrayList<>();
        for (char c : chars)
            list.add(c);
        for(int i=0;i<list.size();i++)
            fn(list,i);
        System.out.println(">>>>>>>>>>>>>>>>>");
        System.out.println(set);
    }
}
